import Core.MongoDB as MongoDB
import Core.Gadget as Gadget
import datetime
#from sklearn.ensemble import RandomForestClassifier
from sklearn import tree
import pandas as pd
import numpy as np
import numpy as np
from sklearn.decomposition import PCA
from sklearn import preprocessing
import copy

# 简单统计收益的20%分位，以便确定决策树的分类（领涨20%标记为1，领跌20%记为-1，其余为0）


database = MongoDB.MongoDB("10.13.38.5", "27017")
datetime1 = datetime.datetime(2016, 1, 1)
datetime1 = Gadget.ToUTCDateTime(datetime1)
datetime2 = datetime.datetime(2017, 1, 1)
datetime2 = Gadget.ToUTCDateTime(datetime2)


#dates = Gadget.GenerateMonthDates(datetime1,datetime2)
#for date in dates:

factor_test1 = pd.DataFrame(database.find("Factor", 'MonthlyReturn', datetime1, datetime2))[['StdDateTime', 'Value']].set_index('StdDateTime')
#factor_test1.columns = ['return']
factor_test2 = pd.DataFrame(database.find("Factor", 'MonthlyExcessReturn', datetime1, datetime2))[['StdDateTime', 'Value']].set_index('StdDateTime')
#factor_test2.columns = ['MonthlyExcessReturn']

#print(factor_test1.describe())
#print(factor_test2.describe())

print(np.percentile(np.array(factor_test1), 20))
print(np.percentile(np.array(factor_test2), 20))
